/**
 * date:2021/02/27
 * author:LeapMary
 * version:2.0
 * description:js常用扩展
 */
layui.define(["element", "layer", "jquery"], function (exports) {
    var element = layui.element,
        layer = layui.layer,
        $ = layui.$;

    var arrayJs = {
        /**
         * 根据一个一维数组中的一些值，来筛选二维数组中某个字段包含这个值的数据。
         * @param direction
         */
        getArrayByOne: function ($arr = [], $data = [], $field = '', $operationMinWidth = 150,role_id = '') {

            var $newData = [];

            $newData.push({type: "checkbox", width: 30});
            if(role_id != 6){
                $newData.push({title: '操作', minWidth: $operationMinWidth, toolbar: '#currentTableBar', align: "center"});
            }

            for (var i in $arr) {
                for (var ii in $data) {
                    if ($data[ii][$field] == $arr[i]) {
                        $newData.push($data[ii]);
                    }
                }
            }
            return $newData;

        },
        /**
         * 根据一个一维数组中的一个值，替换其中一个一维数组
         * @param direction
         */
        doArrayReplaceOneArray: function($cols,$one,$title){
            for(var i in $cols){
                if($cols[i].title == $title){  //替换操作
                    $cols[i] = $one;
                }
            }
            return $cols;
        },
        /**
         * 删除数组中的空值
         * @param direction
         */
        trimSpace: function (array) {
            for (var i = 0; i < array.length; i++) {
                if (array[i] == "" || array[i] == " " || array[i] == null || typeof (array[i]) == "undefined") {
                    array.splice(i, 1);
                    i = i - 1;
                }
            }
            return array;
        }
    };

    exports("arrayJs", arrayJs);
});
